#include "string.h"


void *
memcpy(void *to, const void *from, size_t size)
{
	unsigned int i;

	for (i = 0; i < size; i++)
		((unsigned char *) to)[i] = ((unsigned char *) from)[i];

	return (void *) to;
}

void *
memset(void *block, int c, size_t size)
{
	unsigned int i;

	for (i = 0; i < size; i++)
		((unsigned char *) block)[i] = (unsigned char) c;

	return block;
}

char *
strcpy(char *to, const char *from)
{
	unsigned int i;

	for (i = 0; (to[i] = from[i]) != '\0'; i++)
		;

	return to;
}

char *
strncpy(char *to, const char *from, size_t size)
{
	unsigned int i;

	for (i = 0; i < size && (to[i] = from[i]) != '\0'; i++)
		;

	return to;
}

size_t
strlen(const char *s)
{
	unsigned int i;

	for (i = 0; s[i] != '\0'; i++)
		;

	return i;
}

size_t
strnlen (const char *s, size_t maxlen)
{
	unsigned int i;

	for (i = 0; i < maxlen && s[i] != '\0'; i++)
		;

	return i;
}
/*
int
memcmp(const void *a1, const void *a2, size_t size)
{
	unsigned int i;
	int diff = 0;

	for (i = 0; i < size; i++)
		if ((diff = ((unsigned char *) a2)[i]
					- ((unsigned char *) a1)[i]) != 0)
			return diff;

	return diff;
}
*/
int
strcmp(const char *s1, const char *s2)
{
	unsigned int i;
	int diff = 0;

	for (i = 0; s1[i] != '\0' && s2[i] != '\0'; i++)
		if ((diff = s2[i] - s1[i]) != 0)
			return diff;

	return (s2[i] - s1[i]);
}

int
strncmp (const char *s1, const char *s2, size_t size)
{
	unsigned int i;
	int diff = 0;

	for (i = 0; i < size && s1[i] != '\0' && s2[i] != '\0'; i++)
		if ((diff = s2[i] - s1[i]) != 0)
			return diff;

	return (s2[i] - s1[i]);
}

void
invierte(char * origen, char * destino, int dim)
{
	if(dim==1)
		*destino=*origen;
	else
	{
		invierte(origen+1, destino, dim-1);
		*(destino+dim - 1) = *origen;
	}
}
